package com.zhilianbao.leyaogo.view.widgets;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bql.roundview.RoundTextView;
import com.bql.utils.NumberUtlis;
import com.bql.variousbanner.widget.banner.BaseIndicatorBanner;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 用户引导页View <br>
 * Created by Cyarie on 2015/12/22.
 */
public class UserGuideBanner extends BaseIndicatorBanner<View, UserGuideBanner> {

    @Nullable
    @BindView(R.id.iv_bg_0_bottom)
    ImageView mIvBg0Bottom;
    @Nullable
    @BindView(R.id.iv_bg_0_phone)
    ImageView mIvBg0Phone;
    @Nullable
    @BindView(R.id.iv_bg_0_top)
    ImageView mIvBg0Top;
    @Nullable
    @BindView(R.id.iv_cloud_0_0)
    ImageView mIvCloud00;
    @Nullable
    @BindView(R.id.iv_cloud_0_1)
    ImageView mIvCloud01;
    @Nullable
    @BindView(R.id.iv_cloud_0_2)
    ImageView mIvCloud02;
    @Nullable
    @BindView(R.id.iv_bg_1_bottom)
    ImageView mIvBg1Bottom;
    @Nullable
    @BindView(R.id.iv_bg_1_phone)
    ImageView mIvBg1Phone;
    @Nullable
    @BindView(R.id.iv_bg_1_top)
    ImageView mIvBg1Top;
    @Nullable
    @BindView(R.id.iv_cloud_1_0)
    ImageView mIvCloud10;
    @Nullable
    @BindView(R.id.iv_cloud_1_1)
    ImageView mIvCloud11;
    @Nullable
    @BindView(R.id.iv_cloud_1_2)
    ImageView mIvCloud12;
    @Nullable
    @BindView(R.id.iv_bg_2_bottom)
    ImageView mIvBg2Bottom;
    @Nullable
    @BindView(R.id.iv_bg_2_phone)
    ImageView mIvBg2Phone;
    @Nullable
    @BindView(R.id.iv_bg_2_top)
    ImageView mIvBg2Top;
    @Nullable
    @BindView(R.id.iv_cloud_2_0)
    ImageView mIvCloud20;
    @Nullable
    @BindView(R.id.iv_cloud_2_1)
    ImageView mIvCloud21;
    @Nullable
    @BindView(R.id.iv_cloud_2_2)
    ImageView mIvCloud22;
    @Nullable
    @BindView(R.id.iv_cloud_2_3)
    ImageView mIvCloud23;

    public UserGuideBanner(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public UserGuideBanner(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setBarShowWhenLast(false);
    }

    public UserGuideBanner(Context context) {
        this(context, null, 0);

    }

    @Nullable
    @BindView(R.id.tv_jump)
    RoundTextView mTvJump;


    @Override
    public View onCreateItemView(int position) {
        View contentView = null;
        switch (position) {
            case 0:
                contentView = list.get(0);
                ButterKnife.bind(this, contentView);
                //最上层图片属性
                ViewGroup.LayoutParams top0LayoutParams = mIvBg0Top.getLayoutParams();
                top0LayoutParams.height = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.58);
                mIvBg0Top.setLayoutParams(top0LayoutParams);
                //底部图片属性
                ViewGroup.LayoutParams bottom0LayoutParams = mIvBg0Bottom.getLayoutParams();
                bottom0LayoutParams.height = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.42);
                mIvBg0Bottom.setLayoutParams(bottom0LayoutParams);
                //手机图片属性
                RelativeLayout.LayoutParams phone0LayoutParams = (RelativeLayout.LayoutParams) mIvBg0Phone.getLayoutParams();
                phone0LayoutParams.bottomMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.29);
                mIvBg0Phone.setLayoutParams(phone0LayoutParams);
                //白云1属性
                RelativeLayout.LayoutParams cloud00LayoutParams = (RelativeLayout.LayoutParams) mIvCloud00.getLayoutParams();
                cloud00LayoutParams.leftMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.08);
                cloud00LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.25);
                mIvCloud00.setLayoutParams(cloud00LayoutParams);
                //白云2属性
                RelativeLayout.LayoutParams cloud01LayoutParams = (RelativeLayout.LayoutParams) mIvCloud01.getLayoutParams();
                cloud01LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.09);
                mIvCloud01.setLayoutParams(cloud01LayoutParams);
                //白云3属性
                RelativeLayout.LayoutParams cloud02LayoutParams = (RelativeLayout.LayoutParams) mIvCloud02.getLayoutParams();
                cloud02LayoutParams.rightMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.09);
                cloud02LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.12);
                mIvCloud02.setLayoutParams(cloud02LayoutParams);
                break;
            case 1:
                contentView = list.get(1);
                ButterKnife.bind(this, contentView);
                ViewGroup.LayoutParams top1LayoutParams = mIvBg1Top.getLayoutParams();
                top1LayoutParams.height = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.58);
                mIvBg1Top.setLayoutParams(top1LayoutParams);
                ViewGroup.LayoutParams bottom1LayoutParams = mIvBg1Bottom.getLayoutParams();
                bottom1LayoutParams.height = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.42);
                mIvBg1Bottom.setLayoutParams(bottom1LayoutParams);
                RelativeLayout.LayoutParams phone1LayoutParams = (RelativeLayout.LayoutParams) mIvBg1Phone.getLayoutParams();
                phone1LayoutParams.bottomMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.29);
                mIvBg1Phone.setLayoutParams(phone1LayoutParams);
                //白云1属性
                RelativeLayout.LayoutParams cloud10LayoutParams = (RelativeLayout.LayoutParams) mIvCloud10.getLayoutParams();
                cloud10LayoutParams.leftMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.14);
                cloud10LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.18);
                mIvCloud10.setLayoutParams(cloud10LayoutParams);
                //白云2属性
                RelativeLayout.LayoutParams cloud11LayoutParams = (RelativeLayout.LayoutParams) mIvCloud11.getLayoutParams();
                cloud11LayoutParams.rightMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.09);
                cloud11LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.11);
                mIvCloud11.setLayoutParams(cloud11LayoutParams);
                //白云3属性
                RelativeLayout.LayoutParams cloud12LayoutParams = (RelativeLayout.LayoutParams) mIvCloud12.getLayoutParams();
                cloud12LayoutParams.rightMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.05);
                cloud12LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.32);
                mIvCloud12.setLayoutParams(cloud12LayoutParams);
                break;
            case 2:
                contentView = list.get(2);
                ButterKnife.bind(this, contentView);
                ViewGroup.LayoutParams top2LayoutParams = mIvBg2Top.getLayoutParams();
                top2LayoutParams.height = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.58);
                mIvBg2Top.setLayoutParams(top2LayoutParams);
                ViewGroup.LayoutParams bottom2LayoutParams = mIvBg2Bottom.getLayoutParams();
                bottom2LayoutParams.height = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.42);
                mIvBg2Bottom.setLayoutParams(bottom2LayoutParams);
                RelativeLayout.LayoutParams phone2LayoutParams = (RelativeLayout.LayoutParams) mIvBg2Phone.getLayoutParams();
                phone2LayoutParams.bottomMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.29);
                mIvBg2Phone.setLayoutParams(phone2LayoutParams);
                //白云1属性
                RelativeLayout.LayoutParams cloud20LayoutParams = (RelativeLayout.LayoutParams) mIvCloud20.getLayoutParams();
                cloud20LayoutParams.leftMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.14);
                cloud20LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.29);
                mIvCloud20.setLayoutParams(cloud20LayoutParams);
                //白云2属性
                RelativeLayout.LayoutParams cloud21LayoutParams = (RelativeLayout.LayoutParams) mIvCloud21.getLayoutParams();
                cloud21LayoutParams.leftMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.20);
                cloud21LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.08);
                mIvCloud21.setLayoutParams(cloud21LayoutParams);
                //白云3属性
                RelativeLayout.LayoutParams cloud22LayoutParams = (RelativeLayout.LayoutParams) mIvCloud22.getLayoutParams();
                cloud22LayoutParams.rightMargin = (int) NumberUtlis.mul((double) Utils.getScreenWidth(), 0.16);
                cloud22LayoutParams.topMargin = (int) NumberUtlis.mul((double) Utils.getScreenHeight(), 0.16);
                mIvCloud22.setLayoutParams(cloud22LayoutParams);
                mTvJump.setOnClickListener(v -> {
                    if (listener != null)
                        listener.onJumpClick();
                });
                break;
        }
        return contentView;
    }

    public interface OnJumpClickListener {
        void onJumpClick();
    }

    private OnJumpClickListener listener;


    public void setOnJumpClickListener(OnJumpClickListener listener) {
        this.listener = listener;
    }

}
